﻿using IFRS.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace IFRS.DataAccess.DAL
{
    public class SPR_ISALAMICDEPOSIT
    {
        public DataTable SEARCH_ALL(IslamicDeposit islamicDeposit, Paging paging , bool IFRS_ALLBRANCH , string sIFRS_COST_CENTER , ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@isAllBranch", IFRS_ALLBRANCH));
                lstParams.Add(new SqlParameter("@sCostCenter", sIFRS_COST_CENTER));


                lstParams.Add(new SqlParameter("@DataTypeID", islamicDeposit.DataTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountNo", islamicDeposit.AccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@CostCenter", islamicDeposit.CostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", islamicDeposit.IsConfirmed.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_ISALAMICDEPOSIT_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int IslamicDepositID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@IslamicDepositID", IslamicDepositID));
                dt = Utility.StoredProcDataTable("SPR_ISALAMICDEPOSIT_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(IslamicDeposit islamicDeposit)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@IslamicDepositID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@DataTypeID", islamicDeposit.DataTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@TransactionDate", islamicDeposit.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountNo", islamicDeposit.AccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@CostCenter", islamicDeposit.CostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@GLAccountCode", islamicDeposit.GLAccountCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@CurrencyCode", islamicDeposit.CurrencyCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@StartDeposit", islamicDeposit.StartDeposit.AsDBValue()));
                lstParams.Add(new SqlParameter("@ExpiryDate", islamicDeposit.ExpiryDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@DepositAmount", islamicDeposit.DepositAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAmount", islamicDeposit.FeeAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@ExpenseAmount", islamicDeposit.ExpenseAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", islamicDeposit.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_GSB_PRDCD", islamicDeposit.RP_GSB_PRDCD.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_SOURCE_FILE", islamicDeposit.RP_SOURCE_FILE.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_MAPPING_CD", islamicDeposit.RP_MAPPING_CD.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedDate", islamicDeposit.CreatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBy", islamicDeposit.CreatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", islamicDeposit.CreatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBranch", islamicDeposit.CreatedBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", islamicDeposit.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", islamicDeposit.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", islamicDeposit.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", islamicDeposit.UpdatedBranch.AsDBValue()));

                Utility.ExecuteStoredProc("SPR_ISALAMICDEPOSIT_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(IslamicDeposit islamicDeposit)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@IslamicDepositID", islamicDeposit.IslamicDepositID.AsDBValue()));
                lstParams.Add(new SqlParameter("@DataTypeID", islamicDeposit.DataTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@TransactionDate", islamicDeposit.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountNo", islamicDeposit.AccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@CostCenter", islamicDeposit.CostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@GLAccountCode", islamicDeposit.GLAccountCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@CurrencyCode", islamicDeposit.CurrencyCode.AsDBValue()));
                lstParams.Add(new SqlParameter("@StartDeposit", islamicDeposit.StartDeposit.AsDBValue()));
                lstParams.Add(new SqlParameter("@ExpiryDate", islamicDeposit.ExpiryDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@DepositAmount", islamicDeposit.DepositAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAmount", islamicDeposit.FeeAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@ExpenseAmount", islamicDeposit.ExpenseAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", islamicDeposit.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_GSB_PRDCD", islamicDeposit.RP_GSB_PRDCD.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_SOURCE_FILE", islamicDeposit.RP_SOURCE_FILE.AsDBValue()));
                lstParams.Add(new SqlParameter("@RP_MAPPING_CD", islamicDeposit.RP_MAPPING_CD.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", islamicDeposit.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", islamicDeposit.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", islamicDeposit.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", islamicDeposit.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_ISALAMICDEPOSIT_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
        public int DELETE(IslamicDeposit islamicDeposit)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@IslamicDepositID", islamicDeposit.IslamicDepositID.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", islamicDeposit.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", islamicDeposit.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", islamicDeposit.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", islamicDeposit.UpdatedBranch.AsDBValue()));
                iNum = (int)Utility.ExecuteStoredProc("SPR_ISALAMICDEPOSIT_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}